#pragma once

#include "event_loop.h"
#include "net_callback.h"

namespace rr {
namespace nio {

class TcpConnection : public std::enable_shared_from_this<TcpConnection>
{
public:
    using Sptr = std::shared_ptr<TcpConnection>;

public:
    TcpConnection(EventLoop::Sptr loop, boost::asio::ip::tcp::socket& socket);
    ~TcpConnection();

    void SetConnectionCallback(const ConnectionCallback& cb) { connection_cb_ = cb; }
    void SetCloseCallback(const CloseCallback& cb) { close_cb_ = cb; }

    void SetConnectSuccess();

    int32_t DoClose();

private:
    void DoRead();
    void OnClose();
private:
    EventLoop::Sptr loop_;
    boost::asio::ip::tcp::socket socket_;
    ConnectionCallback connection_cb_ = nullptr;
    CloseCallback close_cb_ = nullptr;
    
    std::vector<uint8_t> read_buf_;
};


} //namespace 
} //namespace 